﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlottingBasics.LINQHelpers;
using System.Linq;

namespace t_PlottingBasics
{
    [TestClass]
    public class t_Adjacent
    {
        [TestMethod]
        public void TestCTor()
        {
            double[] arr = { 1.0, 5.0, 2.0 };
            arr.AdjacentItems(3.0);
        }

        [TestMethod]
        public void TestBasicBehavior()
        {
            double[] arr = { 1.0, 2.0, 5.0 };
            var result = arr.AdjacentItems(3.0);
            Assert.AreEqual(2.0, result._first, "first is not right");
            Assert.AreEqual(5.0, result._second, "second is not right");
        }

        [TestMethod]
        public void TestSort()
        {
            double[] arr = { 1.0, 5.0, 2.0 };
            var result = arr.AdjacentItems(3.0);
            Assert.AreEqual(2.0, result._first, "first is not right");
            Assert.AreEqual(5.0, result._second, "second is not right");
        }

        [TestMethod]
        public void TestStruct()
        {
            Point[] pts = new Point[]{
                new Point(){ X=2.0, Y=3.0},
                new Point(){ X=5.0, Y=1.0},
                new Point(){ X=3.0, Y=5.0}
            };
            var result = pts.AdjacentItems(2.5, p => p.X);
            Assert.AreEqual(3.0, result._first.Y, "wrong y came back for first");
            Assert.AreEqual(5.0, result._second.Y, "wrong y for second");
        }

        [TestMethod]
        public void TestSame()
        {
            double[] arr = { 1.0, 2.0, 5.0 };
            var result = arr.AdjacentItems(2.0);
            Assert.AreEqual(2.0, result._first, "first is not right");
            Assert.AreEqual(2.0, result._second, "second is not right");
        }

        [TestMethod]
        public void TestBeyondEnd()
        {
            double[] arr = { 1.0, 2.0, 5.0 };
            var result = arr.AdjacentItems(10.0);
            Assert.AreEqual(5.0, result._first, "first is not right");
            Assert.AreEqual(default(double), result._second, "second is not right");
        }

        [TestMethod]
        public void TestBeforeFirst()
        {
            double[] arr = { 1.0, 2.0, 5.0 };
            var result = arr.AdjacentItems(-10.0);
            Assert.AreEqual(default(double), result._first, "first is not right");
            Assert.AreEqual(1.0, result._second, "second is not right");
        }
    }
}